#!/usr/bin/env python
"""
这个代码主要是用来解析一个网站的下载地址用的脚手架程序.
"""
import argparse
import sys

import requests
from bs4 import BeautifulSoup

parser = argparse.ArgumentParser(
    usage="python movie_cli.py -q <电影名称>", description="这个代码主要是用来解析一个网站的下载地址用的脚手架程序."
)
parser.add_argument("-q", "--movie_name", help="想查询的电影名称.", default="复仇者联盟")
args = parser.parse_args()
print(args.movie_name)

KEY = args.movie_name

if not KEY:
    print("需要输入影片名称!")
    print("python movie_cli,py --movie_name=<moviename>")
    sys.exit()


print(f"https://xunso.fun/search.html?keyword={KEY}")
resp = requests.get(f"https://xunso.fun/search.html?keyword={KEY}")

# print(resp.text)
soup = BeautifulSoup(resp.text, features="html.parser")

# print(soup.find_all('a'))
links = soup.find_all("a")

if len(links) == 0:
    print(f"no movie `{KEY}` download link.")
else:
    for link in links:
        print(f'{link.get_text()} : {link.get("href")}')
